<?php 
/*
* 侧边栏组件、页面模块
*/
if(!defined('EMLOG_ROOT')) {exit('error!');} 
?>
<?php
//widget：blogger
function widget_blogger($title){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');$name = $user_cache[1]['mail'] != '' ? "<a href=\"mailto:".$user_cache[1]['mail']."\">".$user_cache[1]['name']."</a>" : $user_cache[1]['name'];?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('bloggerinfo')"><?php echo $title; ?></span></h2>
	<ul id="bloggerinfo" class="about">
	<div id="bloggerinfoimg">
	<?php if (!empty($user_cache[1]['photo']['src'])): ?>
	<img src="<?php echo BLOG_URL.$user_cache[1]['photo']['src']; ?>" width="<?php echo $user_cache[1]['photo']['width']; ?>" height="<?php echo $user_cache[1]['photo']['height']; ?>" alt="blogger" />
	<?php endif;?>
	</div>
	<li><b><?php echo $name; ?></b></li>
	<li><?php echo $user_cache[1]['des']; ?></li>
	</ul>
	</li>
<?php }?>
<?php
//widget：日历
function widget_calendar($title){
?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('calendar')"><?php echo $title; ?></span></h2>
	<div id="calendar">
	</div>
	<script>sendinfo('<?php echo Calendar::url(); ?>','calendar');</script>
	</li>
<?php }?>
<?php
//widget：标签
function widget_tag($title){
	global $CACHE;
	$tag_cache = $CACHE->readCache('tags');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('blogtags')"><?php echo $title; ?></span></h2>
	<ul id="blogtags">
	<li>
	<?php foreach($tag_cache as $value): ?>
		<span style="font-size:<?php echo $value['fontsize']; ?>pt; height:30px;">
		<a href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇日志"><?php echo $value['tagname']; ?></a></span>
	<?php endforeach; ?>
	</li>
	</ul>
	</li>
<?php }?>
<?php
//widget：分类
function widget_sort($title){
	global $CACHE;
	$sort_cache = $CACHE->readCache('sort');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('blogsort')"><?php echo $title; ?></span></h2>
	<ul id="blogsort">
	<?php foreach($sort_cache as $value): ?>
	<li>
	<a href="<?php echo Url::sort($value['sid']); ?>"><?php echo $value['sortname']; ?>(<?php echo $value['lognum'] ?>)</a>
	<a href="<?php echo BLOG_URL; ?>rss.php?sort=<?php echo $value['sid']; ?>"><img align="absmiddle" src="<?php echo TEMPLATE_URL; ?>images/icon_rss.gif" alt="订阅该分类"/></a>
	</li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：最新碎语
function widget_twitter($title){
	global $CACHE; 
	$newtws_cache = $CACHE->readCache('newtw');
	$istwitter = Option::get('istwitter'); ?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('twitter')"><?php echo $title; ?></span></h2>
	<ul id="twitter">
	<?php foreach($newtws_cache as $value): ?>
	<li><?php echo $value['t']; ?><p><?php echo smartDate($value['date']); ?> </p></li>
	<?php endforeach; ?>
    <?php if ($istwitter == 'y') :?>
	<p style="text-align:right"><a href="<?php echo BLOG_URL . 't/'; ?>">更多&raquo;</a></p>
	<?php endif;?>
	</ul>
	</li>
<?php }?>
<?php
//widget：最新评论
function widget_newcomm($title){
	global $CACHE;
	$com_cache = $CACHE->readCache('comment');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('newcomment')"><?php echo $title; ?></span></h2>
	<ul id="newcomment">
	<?php
	foreach($com_cache as $value):
	$url = Url::log($value['gid']).'#'.$value['cid'];
	?>
	<li><a href="<?php echo $url; ?>"><?php echo $value['name']; ?></a>: <?php echo $value['content']; ?></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：最新日志
function widget_newlog($title){
	global $CACHE;
	$newLogs_cache = $CACHE->readCache('newlog');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('newlog')"><?php echo $title; ?></span></h2>
	<ul id="newlog">
	<?php foreach($newLogs_cache as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：随机日志
function widget_random_log($title){
	$index_randlognum = Option::get('index_randlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getRandLog($index_randlognum);?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('randlog')"><?php echo $title; ?></span></h2>
	<ul id="randlog">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//widget：归档
function widget_archive($title){
	global $CACHE;
	$dang_cache = $CACHE->readCache('record');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('record')"><?php echo $title; ?></span></h2>
	<ul id="record">
	<?php foreach($dang_cache as $value): ?>
	<li><a href="<?php echo Url::record($value['date']); ?>"><?php echo $value['record']; ?>(<?php echo $value['lognum']; ?>)</a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php } ?>
<?php
//widget：自定义组件
function widget_custom_text($title, $content, $id){ ?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('<?php echo $id; ?>')"><?php echo $title; ?></span></h2>
	<ul id="<?php echo $id; ?>">
	<li><?php echo $content; ?></li>
	</ul>
	</li>
<?php } ?>
<?php
//widget：链接
function widget_link($title){
	global $CACHE;
	$link_cache = $CACHE->readCache('link');?>
	<li class="widget clear">
	<h2 class="widgettitle"><span onclick="showhidediv('link')"><?php echo $title; ?></span></h2>
	<ul id="link">
	<?php foreach($link_cache as $value): ?>
	<li><a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li>
	<?php endforeach; ?>
	</ul>
	</li>
<?php }?>
<?php
//blog：置顶
function topflg($istop){
	$topflg = $istop == 'y' ? "<img src=\"".TEMPLATE_URL."/images/import.gif\" align=\"absmiddle\"  title=\"置顶日志\" /> " : '';
	echo $topflg;
}
?>
<?php
//blog：编辑
function editflg($logid,$author){
	$editflg = ROLE == 'admin' || $author == UID ? '<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'">编辑</a>' : '';
	echo $editflg;
}
?>
<?php
//blog：分类
function blog_sort($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
	<a href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>
	<?php endif;?>
<?php }?>
<?php
//blog：文件附件
function blog_att($blogid){
	global $CACHE;
	$log_cache_atts = $CACHE->readCache('logatts');
	$att = '';
	if(!empty($log_cache_atts[$blogid])){
		$att .= '附件下载：';
		foreach($log_cache_atts[$blogid] as $val){
			$att .= '<br /><a href="'.BLOG_URL.$val['url'].'" target="_blank">'.$val['filename'].'</a> '.$val['size'];
		}
	}
	echo $att;
}
?>
<?php
//blog：日志标签
function blog_tag($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid]))
	{
		$tag = '标签:';
		foreach ($log_cache_tags[$blogid] as $value)
		{
			$tag .= "	<a href=\"".BLOG_URL."?tag=".$value['tagurl']."\">".$value['tagname'].'</a>';
		}
		echo $tag;
	}
}
?>
<?php
//blog：日志作者
function blog_author($uid){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$author = $user_cache[$uid]['name'];
	$mail = $user_cache[$uid]['mail'];
	$des = $user_cache[$uid]['des'];
	$title = !empty($mail) || !empty($des) ? "title=\"$des $mail\"" : '';
	echo '<a href="'.Url::author($uid)."\" $title>$author</a>";
}
?>
<?php
//blog：相邻日志
function neighbor_log($neighborLog){
	extract($neighborLog);?>
	<div class="clear">
	<span class="align_left">
	<?php if($prevLog):?>
	&laquo; 上一篇：<a href="<?php echo Url::log($prevLog['gid']) ?>"><?php echo $prevLog['title'];?></a>
	<?php else: ?>
	&laquo; 上一篇：<a href="javascript:void(0);">没有了</a>
	<?php endif;?>
	</span>
	<span class="align_right">
	<?php if($nextLog):?>
	<a href="<?php echo Url::log($nextLog['gid']) ?>"><?php echo $nextLog['title'];?></a>：下一篇 &raquo;
	<?php else: ?>
	<a href="javascript:void(0);">没有了</a>：下一篇 &raquo;
	<?php endif;?>
	</span>
	</div>
<?php }?>
<?php
//blog：博客评论列表
function blog_comments($comments){
    extract($comments);
	?>
	<?php if($comments): ?>
	<ol class="commentlist">
	<?php endif; ?>
	<?php
	foreach($comments as $key=>$value):
	$value['poster'] = $value['url'] ? '<a href="'.$value['url'].'" target="_blank">'.$value['poster'].'</a>' : $value['poster'];
	?>
	<li class="comment depth-1" id="comment-<?php echo $value['cid']; ?>">
	<div class="commentmetadata" id="div-comment-<?php echo $value['cid']; ?>">
		<ul class="comminfo clear">
			<li><img width="32" height="32" src="http://www.gravatar.com/avatar/<?php echo md5($value['mail']); ?>?s=32&d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G" /></li>
			<li class="atxt">
				<span><?php echo $value['poster']; ?></span>
				<p>发表于 <?php echo $value['date']; ?></p>
			</li>
		</ul>
		<ul class="commtext clear">
			<p><?php echo $value['content']; ?></p>
		</ul>
	</div>
	</li>
	<?php endforeach; ?>
	<?php if($comments): ?>
	</ol>	
	<?php endif; ?>
<?php }?>
<?php
//blog：发表评论表单
function blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark){?>
	<?php if($allow_remark == 'y'): ?>
	<div id="respond">
	<div class="loginin"><h4 class="clear">发表我的评论</h4></div>
	<form method="post"  name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">
	<input type="hidden" name="gid" value="<?php echo $logid; ?>" />
	<?php if ( $ckname != "" ) : ?>
	<div id="welcome">
		欢迎 <strong><?php echo $ckname; ?></strong> 归来!
	</div>
	<?php endif; ?>
	<?php if(ROLE == 'visitor'): ?>
	<div id="author_info">
	<p><input type="text" name="comname" id="author" value="<?php echo $ckname; ?>" size="22" tabindex="1"/>
	<label for="author">昵称(必填)</label></p>

	<p><input type="text" name="commail" id="email" value="<?php echo $ckmail; ?>" size="22" tabindex="2"/>
	<label for="email">邮箱(必填)</label></p>

	<p><input type="text" name="comurl" id="url" value="<?php echo $ckurl; ?>" size="22" tabindex="3" />
	<label for="url">个人主页</label></p>
	</div>
	<?php endif;?>
	<p><textarea name="comment" id="comment" cols="5" rows="10" tabindex="4" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('submit').click();return false};"></textarea></p>
	<p><?php echo $verifyCode; ?><input type="submit" id="submit" class="subin" value="" /></p>
	</form>
	</div>
	<?php endif; ?>
<?php }?>